package com.five.sbgroup5job.service.impl;
//呼卓盈

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.sbgroup5job.entity.Staff;
import com.five.sbgroup5job.mapper.StaffMapper;
import com.five.sbgroup5job.service.StaffService;
import com.five.sbgroup5job.vo.StaffVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff>
        implements StaffService {

    @Resource
    private StaffMapper staffMapper;

    @Override
    public List<Staff> staffList() {return staffMapper.selectList(null);
    }


    //添加
    @Override
    public String staffAdd(StaffVo staffVo) {
        Staff staff = new Staff();
        staff.setName(staffVo.getName());
        staff.setSex(staffVo.getSex());
        staff.setPhone(staffVo.getPhone());
        staff.setAddress(staffVo.getAddress());
        staff.setDuty(staffVo.getDuty());
        staff.setCondition(staffVo.getCondition());
        int result = staffMapper.insert(staff);
        if(result>0){
            return "添加成功";
        }else{
            return "添加失败";
        }

    }

    //更新
    @Override
    public String staffUpdate(StaffVo staffVo) {

        Staff staff = new Staff();
        staffVo.setName(staffVo.getName());
        staffVo.setAddress(staffVo.getAddress());
        staffVo.setPhone(staffVo.getPhone());
        staffVo.setCondition(staffVo.getCondition());
        staffVo.setDuty(staffVo.getDuty());
        int result = staffMapper.updateById(staff);

        if(result>0){
            return "更新成功";
        }else{
            return "更新失败";
        }
    }

    //删除用户
    @Override
    public String staffDelete(StaffVo staffVo) {

        int result = staffMapper.deleteById(staffVo.getName());
        int result1 = staffMapper.deleteById(staffVo.getName());
        int result2 = staffMapper.deleteById(staffVo.getName());
        int result3 = staffMapper.deleteById(staffVo.getName());
        if(result>0){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

}




